<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分布式定时任务管理系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .sidebar {
            min-height: 100vh;
            background-color: #343a40;
        }
        .sidebar .nav-link {
            color: #adb5bd;
        }
        .sidebar .nav-link:hover {
            color: #ffffff;
        }
        .sidebar .nav-link.active {
            color: #ffffff;
            background-color: #007bff;
        }
        .content {
            padding: 20px;
        }
        .status-badge {
            display: inline-block;
            padding: 0.2em 0.6em;
            font-size: 0.75em;
            font-weight: 700;
            line-height: 1;
            text-align: center;
            white-space: nowrap;
            vertical-align: baseline;
            border-radius: 0.25rem;
        }
        .status-running { background-color: #28a745; color: white; }
        .status-stopped { background-color: #6c757d; color: white; }
        .status-disabled { background-color: #dc3545; color: white; }
        
        /* emoji 图标样式 */
        .nav-link {
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <!-- 侧边栏 -->
            <div class="col-md-2 sidebar">
                <div class="sidebar-sticky pt-3">
                    <h5 class="text-white text-center mb-3">调度管理系统</h5>
                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link active" href="#" onclick="showPage('dashboard')">
                                📊 系统概览
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#" onclick="showPage('jobs')">
                                📋 任务管理
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#" onclick="showPage('logs')">
                                📄 执行日志
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#" onclick="showPage('cluster')">
                                🖥️ 集群节点
                            </a>
                        </li>
                    </ul>
                </div>
            </div>

            <!-- 主内容区域 -->
            <div class="col-md-10 content">
                <!-- 系统概览页面 -->
                <div id="dashboard-page" class="page-content">
                    <h2>系统概览</h2>
                    <div class="row mt-4">
                        <div class="col-md-3">
                            <div class="card text-white bg-primary">
                                <div class="card-body">
                                    <h5 class="card-title">活跃节点</h5>
                                    <h2 id="active-nodes-count">-</h2>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="card text-white bg-info">
                                <div class="card-body">
                                    <h5 class="card-title">总任务数</h5>
                                    <h2 id="total-jobs-count">-</h2>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="card text-white bg-success">
                                <div class="card-body">
                                    <h5 class="card-title">运行中任务</h5>
                                    <h2 id="running-jobs-count">-</h2>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="card text-white bg-warning">
                                <div class="card-body">
                                    <h5 class="card-title">系统负载</h5>
                                    <h2>正常</h2>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 任务管理页面 -->
                <div id="jobs-page" class="page-content" style="display: none;">
                    <div class="d-flex justify-content-between align-items-center mb-3">
                        <h2>任务管理</h2>
                        <button class="btn btn-primary" onclick="showAddJobModal()">
                            ➕ 新增任务
                        </button>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>任务描述</th>
                                    <th>Cron表达式</th>
                                    <th>执行类</th>
                                    <th>状态</th>
                                    <th>运行状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody id="jobs-table-body">
                                <!-- 动态加载任务列表 -->
                            </tbody>
                        </table>
                    </div>
                </div>

                <!-- 执行日志页面 -->
                <div id="logs-page" class="page-content" style="display: none;">
                    <h2>执行日志</h2>
                    <div class="table-responsive mt-3">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th>日志ID</th>
                                    <th>任务ID</th>
                                    <th>执行节点</th>
                                    <th>触发时间</th>
                                    <th>处理时间</th>
                                    <th>触发状态</th>
                                    <th>处理状态</th>
                                    <th>执行结果</th>
                                </tr>
                            </thead>
                            <tbody id="logs-table-body">
                                <!-- 动态加载日志列表 -->
                            </tbody>
                        </table>
                    </div>
                </div>

                <!-- 集群节点页面 -->
                <div id="cluster-page" class="page-content" style="display: none;">
                    <h2>集群节点</h2>
                    <div class="table-responsive mt-3">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th>节点ID</th>
                                    <th>节点地址</th>
                                    <th>最后更新时间</th>
                                    <th>状态</th>
                                </tr>
                            </thead>
                            <tbody id="cluster-table-body">
                                <!-- 动态加载集群节点列表 -->
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 新增/编辑任务模态框 -->
    <div class="modal fade" id="jobModal" tabindex="-1">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="jobModalTitle">新增任务</h5>
                    <button type="button" class="close" data-dismiss="modal">
                        <span>&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form id="jobForm">
                        <input type="hidden" id="jobId" name="id">
                        <div class="form-group">
                            <label for="jobDesc">任务描述 *</label>
                            <input type="text" class="form-control" id="jobDesc" name="jobDesc" required>
                        </div>
                        <div class="form-group">
                            <label for="jobCron">Cron表达式 *</label>
                            <input type="text" class="form-control" id="jobCron" name="jobCron" required 
                                   placeholder="例：0/10 * * * * ? (每10秒执行一次)">
                        </div>
                        <div class="form-group">
                            <label for="jobClassName">执行类名 *</label>
                            <select class="form-control" id="jobClassName" name="jobClassName" required>
                                <option value="">请选择执行类</option>
                                <option value="SampleJobHandler">SampleJobHandler - 示例任务处理器</option>
                                <option value="PrintJobHandler">PrintJobHandler - 打印任务处理器</option>
                                <option value="ServiceMonitoringJobHandler">ServiceMonitoringJobHandler - 服务状态监控</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="jobParam">任务参数</label>
                            <textarea class="form-control" id="jobParam" name="jobParam" rows="3" 
                                      placeholder='JSON格式，例：{"message":"Hello World"}'></textarea>
                        </div>
                        <div class="form-group">
                            <label for="jobGroup">任务分组</label>
                            <input type="text" class="form-control" id="jobGroup" name="jobGroup" value="default">
                        </div>
                        <div class="form-group">
                            <label for="author">负责人</label>
                            <input type="text" class="form-control" id="author" name="author" value="admin">
                        </div>
                        <div class="form-group">
                            <label for="alarmEmail">告警邮箱</label>
                            <input type="email" class="form-control" id="alarmEmail" name="alarmEmail">
                        </div>
                        <div class="form-group">
                            <label for="executorFailRetryCount">失败重试次数</label>
                            <input type="number" class="form-control" id="executorFailRetryCount" 
                                   name="executorFailRetryCount" value="0" min="0" max="10">
                        </div>
                        <div class="form-group">
                            <label for="executorTimeout">执行超时时间(秒)</label>
                            <input type="number" class="form-control" id="executorTimeout" 
                                   name="executorTimeout" value="0" min="0" placeholder="0表示不限制">
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" onclick="saveJob()">保存</button>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.4/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
    <script src="js/app.js"></script>
</body>
</html>